<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD><TITLE>lassign manual page - Tcl Built-In Commands</TITLE>
<link rel="stylesheet" href="../docs.css" type="text/css" media="all">
</HEAD>
<BODY><H2><a href="../contents.htm">Tcl8.6.11/Tk8.6.11 Documentation</a> <small>&gt;</small> <a href="contents.htm">Tcl Commands</a> <small>&gt;</small> lassign</H2>
<H3><A HREF="../UserCmd/contents.htm">Tcl/Tk Applications</A> | <A HREF="../TclCmd/contents.htm">Tcl Commands</A> | <A HREF="../TkCmd/contents.htm">Tk Commands</A> | <A HREF="../ItclCmd/contents.htm">[incr Tcl] Package Commands</A> | <A HREF="../SqliteCmd/contents.htm">SQLite3 Package Commands</A> | <A HREF="../TdbcCmd/contents.htm">TDBC Package Commands</A> | <A HREF="../TdbcmysqlCmd/contents.htm">tdbc::mysql Package Commands</A> | <A HREF="../TdbcodbcCmd/contents.htm">tdbc::odbc Package Commands</A> | <A HREF="../TdbcpostgresCmd/contents.htm">tdbc::postgres Package Commands</A> | <A HREF="../TdbcsqliteCmd/contents.htm">tdbc::sqlite3 Package Commands</A> | <A HREF="../ThreadCmd/contents.htm">Thread Package Commands</A> | <A HREF="../TclLib/contents.htm">Tcl C API</A> | <A HREF="../TkLib/contents.htm">Tk C API</A> | <A HREF="../ItclLib/contents.htm">[incr Tcl] Package C API</A> | <A HREF="../TdbcLib/contents.htm">TDBC Package C API</A></H3>
<H3><A NAME="M2">NAME</A></H3>
lassign &mdash; Assign list elements to variables
<H3><A NAME="M3">SYNOPSIS</A></H3>
<B>lassign </B><I>list </I>?<I>varName ...</I>?<BR>
<H3><A NAME="M4">DESCRIPTION</A></H3>
This command treats the value <I>list</I> as a list and assigns
successive elements from that list to the variables given by the
<I>varName</I> arguments in order.  If there are more variable names
than list elements, the remaining variables are set to the empty
string.  If there are more list elements than variables, a list of
unassigned elements is returned.
<H3><A NAME="M5">EXAMPLES</A></H3>
An illustration of how multiple assignment works, and what happens
when there are either too few or too many elements.
<P>
<PRE><B>lassign</B> {a b c} x y z       ;# Empty return
puts $x                     ;# Prints &quot;a&quot;
puts $y                     ;# Prints &quot;b&quot;
puts $z                     ;# Prints &quot;c&quot;

<B>lassign</B> {d e} x y z         ;# Empty return
puts $x                     ;# Prints &quot;d&quot;
puts $y                     ;# Prints &quot;e&quot;
puts $z                     ;# Prints &quot;&quot;

<B>lassign</B> {f g h i} x y       ;# Returns &quot;h i&quot;
puts $x                     ;# Prints &quot;f&quot;
puts $y                     ;# Prints &quot;g&quot;</PRE>
<P>
The <B>lassign</B> command has other uses.  It can be used to create
the analogue of the
&ldquo;shift&rdquo;
command in many shell languages like this:
<P>
<PRE>set ::argv [<B>lassign</B> $::argv argumentToReadOff]</PRE>
<H3><A NAME="M6">SEE ALSO</A></H3>
<B><A HREF="../TclCmd/lindex.htm">lindex</A></B>, <B><A HREF="../TclCmd/list.htm">list</A></B>, <B><A HREF="../TclCmd/lrange.htm">lrange</A></B>, <B><A HREF="../TclCmd/lset.htm">lset</A></B>, <B><A HREF="../TclCmd/set.htm">set</A></B>
<H3><A NAME="M7">KEYWORDS</A></H3>
<A href="../Keywords/A.htm#assign">assign</A>, <A href="../Keywords/E.htm#element">element</A>, <A href="../Keywords/L.htm#list">list</A>, <A href="../Keywords/M.htm#multiple">multiple</A>, <A href="../Keywords/S.htm#set">set</A>, <A href="../Keywords/V.htm#variable">variable</A>
<div class="copy">Copyright &copy; 1992-1999 Karl Lehenbauer &amp; Mark Diekhans
<BR>Copyright &copy; 2004 Donal K. Fellows
</div>
</BODY></HTML>
